/* D音H5发布 api */
import request from '@/utils/request';
import {object2Url} from "@/utils/trans";

// 创建发布任务
export async function publishCreate (data) {
  const res = await request.post('/business/matrix/dypublish/create', data)
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

// 添加发布任务账号(抖音/快手u通用)
export async function publishAdd (data) {
  const res = await request.post('/business/matrix/publishaccount/add', data)
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

// 添加发布任务账号(快手)——暂未使用该接口
export async function publishKsAdd (data) {
  const res = await request.post('/business/matrixkspublish/add', data)
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

// 获取发布任务账号【分页】
export async function publishPage (data) {
  const res = await request.post('/business/matrix/publishaccount/page', data)
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


// 获取发布任务账号【分页】
export async function publishPageQuery (data) {
  const res = await request.post('/business/matrix/publishaccount/page', data)
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

// 获取发布任务账号【分页】（修改，且查看总数）
export async function getEventDetails (data) {
  const res = await request.post('/business/MerchantManagement/getEventDetails', data)
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

// 爆客码——活动列表——数据详情
/*export async function getEventDetails (data) {
  const res = await request.post('/business/MerchantManagement/getEventDetails', data)
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}*/


// 爆客码——活动列表——数据详情
export async function douyinShare (data) {
  const res = await request.post('/business/matrix/dypublish/douyin/h5', data)
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

// 矩阵发布列表——查询视频评论
export async function dyCommentList(item) {
  console.log("item",item)
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
    limit: item.limit,
    page: item.page,
    id: item.id
  };
  // ${object2Url(us)} get 链接传值
  let url = `/business/matrix/dypublish/douyin/commentList${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/*export async function dyCommentList (data) {
  const res = await request.post('/business/matrix/dypublish/douyin/commentList', data)
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}*/

// 获取任务发布账号【所有】
export async function publishList(type) {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
    type: type
  };
  // ${object2Url(us)} get 链接传值
  let url = `/business/matrix/publishaccount/list${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}



// 传参poi
//ts(string) 当前时间戳
// ua(string) 浏览器标识
// keyword(string) 查询地理位置关键词
// city(string) 所属城市
// cursor(int) 游标第一页为0，后续页游标在响应数据中获取
// count(int) 每页展示数量

// 查询D音POI
export async function dyPoi(keyword,city,cursor,count) {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
    cursor:cursor,
    keyword:keyword,
    city: city,
    count:count
  };
  // ${object2Url(us)} get 链接传值
  let url = `/business/matrix/dypublish/poi${object2Url(us)}`
  const res = await request.get(url, us);
  console.log('res=======',res)
  if (res.data.code === 2000) {
    // return res.data.data.data.pois;
    return res.data.data;
  }
  return Promise.reject(new Error(res.data));
}



// 获取任务发布账号【去重】
export async function publishExistList(type) {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
    type: type
  };
  // ${object2Url(us)} get 链接传值
  let url = `/business/matrix/publishaccount/list/exist${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 根据ID加载发布任务
export async function publishLoad(type) {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
    type: type
  };
  // ${object2Url(us)} get 链接传值
  let url = `/business/matrix/dypublish/load${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 删除发布任务账号
export async function delPublishAccount (data) {
  const res = await request.post('/business/matrix/publishaccount/delete', data)
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

// 删除发布任务
export async function delPublish (data) {
  const res = await request.post('/business/matrix/dypublish/delete', data)
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

// 修改发布任务
export async function updatePublish (data) {
  const res = await request.post('/business/matrix/dypublish/update', data)
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}
